<?php
class defaultParametersFilter extends sfFilter
{
  public function execute ($filterChain)
  {
    $request = $this->getContext()->getRequest();
    if ($this->isFirstCall() && !$request->hasParameter('filtres'))
    {
      try
      {
        $dateFrom = LogPeer::getLastImportedDate();
      }
      catch (sfException $ex)
      {
        $dateFrom = new DateTime(date('Y-m-d'));
      }

      $dateTo = clone $dateFrom;
      $dateTo->modify("+1 day");

      $from = array(
        'month' => ltrim($dateFrom->format('m'), '0'),
        'day'   => ltrim($dateFrom->format('d'), '0'),
        'year'  => $dateFrom->format('Y'),
      );
      $to = array(
        'month' => ltrim($dateTo->format('m'), '0'),
        'day'   => ltrim($dateTo->format('d'), '0'),
        'year'  => $dateTo->format('Y'),
      );

      $filtres = array(
        'periode' => array(
          'from' => $from,
          'to'   => $to,
        ),
        'type'    => 'Non',
        'grouper' => 0,
        'machine' => 'Non',
        'user'    => 'Non',
      );

      $request->setParameter('filtres', $filtres);
      /** @see sfPatternRouting::generate */
      $url = $this->context->getRouting()->generate('homepage', array('filtres' => $filtres), true);
      $this->getContext()->getController()->redirect($url);
    }
    $filterChain->execute();
  }
}